<template>
  <Dialog
    ref="dialogg"
    :title="'选择部门'"
    :dialogStyle="{ width: '400px', height: '550px' }"
    :modal="true"
    :draggable="true"
    :resizable="true"
  >
    <div style="height:100%">
      <sidebar-dept
        ref="sidebarDept"
        :treeId="treeId"
        :treeHeight="treeHeight"
        :showUserList="showUserList"
        :onZTreeClick="onZTreeCheck"
        :enable="false"
      />
    </div>
    
    <div slot="footer" style="border:none">
        <div class="footerDiv" style="padding:10px 0 10px 0">
            <!-- footer、footerDiv这两个div必须保留 -->
            <LinkButton @click="handleOk" class="saveBtn">保存</LinkButton>
            <span style="margin:0px 10px;"/>
            <LinkButton @click="handleCancel" class="cancelBtn">取消</LinkButton>
        </div>
    </div>
  </Dialog>
</template>

<script>
import sidebarDept from "@/components/dept/sidebarDept";

export default {
  components: {
    sidebarDept
  },
  props: {
    isOpen: {
      type: Boolean,
      default: false
    },
    select: Function,
    treeId: String,
    treeHeight: String,
    showUserList: {
      type: Boolean,
      default: true
    },
    onZTreeCheck: {
      type: Function,
      default: null
    }
  },
  data () {
    return {
      callOk: null
    }
  },
  mounted() {
    this.$refs.dialogg.close();
  },
  methods: {
    open(callback) {
      this.callOk = callback;
      this.$refs.dialogg.open();
    },
    close() {
      this.$refs.dialogg.close();
    },
    //点击确定
    handleOk() {
      // 单选最后节点部门
      let selected = this.$refs.sidebarDept.getSelectDept();
      // console.log(selected);
      if (selected == null || selected == undefined || selected.length == 0) { 
        //  || selected.isParent    判断是不是父级节点
        this.$messager.alert({
          title: "提示",
          icon: "info",
          msg: "请选择部门!"
        });
        return
      } else {
        //回调返回选中树形节点
        this.callOk(selected[0]);
        //关闭对话框
        this.$refs.dialogg.close();
        selected = null;
      }
    },
    //点击返回
    handleCancel() {
      //关闭对话框
      this.$refs.dialogg.close();
    }
  }
};
</script>
